package novel.common.utils;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class OkttpUtil {
    public static String postData(String url, String page) {
        try {
            OkHttpClient client = new OkHttpClient().newBuilder()
                    .build();
            MediaType mediaType = MediaType.parse("application/json");
            RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
                    .addFormDataPart("page", page)
                    .build();
            Request request = new Request.Builder()
                    .url("https://zhishuapi.aldwx.com/Main/action/Dashboard/Homepage/newsFlash")
                    .method("POST", body)
                    .addHeader("Content-Type", "application/json")
                    .addHeader("BWTOKEN", "aiinvoice_8af4f558526d436a937d67f7a77d2d56")
                    .build();
            Response response = client.newCall(request).execute();
            String res = response.body().string();
            return res;
        } catch (Exception e) {
            return "";
        }
    }
}
